package com.ac.util;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ConfUtils {

	/**
	 * 是否是正式部署环境
	 */
	public static boolean pro = false;

	/**
	 * 是否是linux环境
	 */
	public static boolean linux = false;

	/**
	 * 配置列表
	 */
	public static Map<String, String> map;

	public static void setConf(String[] args) {
		Pattern p = Pattern.compile("\\-*(\\D+)");
		map = new HashMap<String, String>();
		for (String str : args) {
			String[] sp = str.split("=");
			String key = null;
			String val = null;
			if (sp.length == 2) {
				val = sp[1];
				Matcher mc = p.matcher(sp[0]);
				if (mc.find()) {
					key = mc.group(1);
				}
			} else {
				key = str;
			}
			map.put(key, val);
		}

		linux = getConfBool("linux");
		pro = getConfBool("pro");

	}

	public static boolean getConfBool(String name) {
		String val = map.get(name);
		return val != null ? val.equals("true") : map.containsKey(name);
	}

}
